local skel = fk.CreateSkill {
  name = "lb__guantou",
}

Fk:loadTranslationTable {
  ["lb__guantou"] = "罐头",
  --[":lb__guantou"] = "出牌阶段限一次，你可以弃置一名角色的一张牌，然后若其体力上限小于5，其增加1点体力上限，否则其摸两张牌。",
  --9.23
  --[":lb__guantou"] = "出牌阶段每名角色限一次，你可以弃置一名角色的一张牌，然后若其体力上限小于5，其增加1点体力上限，否则其摸两张牌。",
  --9.30
  [":lb__guantou"] = "出牌阶段限一次，你可以依次弃置至多两名角色各一张牌，然后若其体力上限小于5，其增加1点体力上限，否则其摸两张牌。",


  --["#lb__guantou"] = "罐头：你可以弃置一名角色的一张牌，令其增加体力上限或摸两张牌",
  ["#lb__guantou"] = "罐头：你可以依次弃置至多两名角色各一张牌，令其增加体力上限或摸两张牌",
  ["#lb__guantou-ask"] = "罐头：弃置%dest一张牌",
  ["#lb__guantou-dis"] = "罐头：你可以弃置除%dest外一名角色的一张牌，令其增加体力上限或摸两张牌",

  ["$lb__guantou1"] = "补充点盐分。",
  ["$lb__guantou2"] = "放松深呼吸。",
}

skel:addEffect("active", {
  anim_type = "support",
  prompt = "#lb__guantou",
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.phase) < 1
    --[[
    table.find(Fk:currentRoom().alive_players, function (to)
      return not table.contains(player:getTableMark("lb__guantou-phase"), to.id)
    end)
    --]]
  end,
  min_target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and not to_select:isNude()
    --and not table.contains(player:getTableMark("lb__guantou-phase"), to_select.id)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local tos = {}
    --room:addTableMark(player, "lb__guantou-phase", target.id)
    repeat
      table.insert(tos, target)
      local card = room:askToChooseCard(player, {
        target = target,
        flag = "he",
        skill_name = skel.name,
        prompt = "#lb__guantou-ask::" .. target.id,
      })
      room:throwCard(card, skel.name, target, player)
      local ts = table.filter(room:getAlivePlayers(), function(to)
        return to ~= target and not to:isNude()
      end)
      if #tos == 1 and player:isAlive() and #ts > 0 then
        local target_ = room:askToChoosePlayers(player, {
          targets = ts,
          min_num = 1,
          max_num = 1,
          skill_name = skel.name,
          cancelable = true,
          prompt = "#lb__guantou-dis::" .. target.id,
        })
        if #target_ > 0 then
          target = target_[1]
        else
          break
        end
      else
        break
      end
    until #tos == 2
    --[[
    if target.maxHp < 5 then
      room:changeMaxHp(target, 1)
    else
      target:drawCards(2, skel.name)
    end
    --]]
    room:sortByAction(tos)
    if player.dead then return end
    for _, to in ipairs(tos) do
      if to:isAlive() then
        if to.maxHp < 5 then
          room:changeMaxHp(to, 1)
        else
          to:drawCards(2, skel.name)
        end
      end
    end
  end,
})

return skel
